package com.bai.translation;

/**
 * @Author: baixfei
 * @Date: 2024/5/20
 * @Time: 10:03
 **/
import java.io.*;
import java.util.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;

public class UntranslatedExcelGenerator {

    public static void generateUntranslatedExcel(List<String> untranslated, String outputPath) throws IOException {
        try (Workbook workbook = new XSSFWorkbook()) {
            Sheet sheet = workbook.createSheet("Untranslated");

            int rowNum = 0;
            for (String untranslatedText : untranslated) {
                Row row = sheet.createRow(rowNum++);
                row.createCell(0).setCellValue(untranslatedText);
                row.createCell(1).setCellValue(""); // English translation not provided
            }

            try (FileOutputStream fos = new FileOutputStream(outputPath)) {
                workbook.write(fos);
            }
        }
    }

    public static Map<String, String> loadTranslationsFromExcel(String excelPath) throws IOException {
        Map<String, String> translations = new HashMap<>();

        try (Workbook workbook = new XSSFWorkbook(new FileInputStream(excelPath))) {
            Sheet sheet = workbook.getSheetAt(0);
            for (Row row : sheet) {
                Cell chineseCell = row.getCell(0);
                Cell englishCell = row.getCell(1);
                if (chineseCell != null && englishCell != null) {
                    translations.put(chineseCell.getStringCellValue(), englishCell.getStringCellValue());
                }
            }
        }

        return translations;
    }
}


